#!/bin/bash

wmbt_home='/home/nlp/nlp/wmbt'
morfeusz_analyzer='/home/nlp/nlp/numbers/morfeusz.py'
parser_wmbt_format='/home/nlp/nlp/numbers/main.py'
sources_dir='/home/nlp/nlp/numbers/sources'
tmp_dir='/home/nlp/nlp/numbers/tmp'
results_dir='/home/nlp/nlp/numbers/results'
current_dir=`pwd`

if [ ! -d "$wmbt_home" ]; then
  echo 'ERORR: missing wmbt directory. Expected: '$wmbt_home
  exit 1
fi

if [ ! -d "$sources_dir" ]; then
  echo 'ERORR: missing sources directory. Expected: '$sources_dir
  exit 1
fi

if [ ! -d "$tmp_dir" ]; then
  echo 'ERORR: missing tmp directory. Expected: '$tmp_dir
  exit 1
fi

if [ ! -d "$results_dir" ]; then
  echo 'ERORR: missing results directory. Expected: '$results_dir
  exit 1
fi

# Clean up
cd $tmp_dir
rm -rf *
cd $results_dir
rm -rf *
cd $current_dir

function process {
  # $1 - input file with plain text
  # $2 - tmp file
  # $3 - output file
  #maca-analyse morfeusz-nkjp-official-guesser -qs < $1 > $2"_maca" -o xces
  #$wmbt_home/wmbt/wmbt.py -d $wmbt_home/model_nkjp10_guess/ $wmbt_home/config/nkjp-guess.ini $2"_maca" -O $2"_wmbt"
  python $morfeusz_analyzer $1 $2"_wmbt"
  python $parser_wmbt_format $2"_wmbt" $3
}

for f in `ls $sources_dir`
do
  echo "Processing $sources_dir/$f"
  process "$sources_dir/$f" "$tmp_dir/$f" "$results_dir/$f" 
done

echo 'Results are in '$results_dir
echo 'Done'

